if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
	var htmltest=document.getElementsByTagName('head')[0].innerHTML;
	if(htmltest.match(RegExp(/format=html5/))){
		var wapurl=htmltest.match(/format=html5; url=(.+?)"/)[1];
		location.href=wapurl;
	}
}
function setCookie(c_name,value,expiredays)
{
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+365)
    document.cookie=c_name+ "=" +escape(value)+";expires="+exdate.toGMTString()+";path=/";
}

function getCookie(c_name)
{
    if (document.cookie.length>0){
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1){ 
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        } 
    }
    return "";
}
function delCookie(name) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null)
	document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
var bookUserName=getCookie("username");
function search(){
	document.writeln("<div class=\"search\">");
	document.writeln("	<form action=\"/s\" onsubmit=\"if(q.value==\'\'){alert(\'提示：请输入小说名称或作者名字！\');return false;}\">");
	document.writeln("	<input type=\"search\" class=\"text\" name=\"q\" placeholder=\"可搜书名和作者，请您少字也别输错字。\" value=\"\" />");
	document.writeln("	<input type=\"submit\" class=\"btn\" value=\"\">");
	document.writeln("	</form>");
	document.writeln("</div>");
}

function tj(){
	var head = "<div class=\'wrap\'><div class=\'topcase\'><a href=\'javascript:setHome();\'>将本站设为首页</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\'javascript:topCase();\'>收藏本站</a></div>";
	if(bookUserName != '' && bookUserName != undefined){
		head += "<div class=\'toplogin\'>欢迎您："+bookUserName+"&nbsp;&nbsp;<a href=\'/user/bookcase.html\'>我的书架</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\'javascript:logout();\'>退出登录</a></div>";
	}else{
		head += "<div class=\'toplogin\'><a class=\'loginbtn\' href=\'/login.html\'>登陆</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\'/register.html\'>用户注册</a></div>";
	}
	$(".header_top").html(head+'</div>');

var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?816fc91a7843e2ae01fe367d0d91cc9c";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();

	(function(){
		var bp = document.createElement('script');
		var curProtocol = window.location.protocol.split(':')[0];
		if (curProtocol === 'https') {
			bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
		}
		else {
			bp.src = 'http://push.zhanzhang.baidu.com/push.js';
		}
		var s = document.getElementsByTagName("script")[0];
		s.parentNode.insertBefore(bp, s);
	})();
}
function lists(id){
	$(".listmain .more").click(function(){$(".listmain .dd_hide").show();$(".listmain .more").hide();});
	$(".noshow").hide();$(".allshow").click(function(){$(".noshow").show();$(".allshow").hide();});
	$(".comment_hide").hide();$(".comment_more").click(function(){$(".comment_hide").show();$(".comment_more").hide();});
	new Image().src = '/hm.gif?id='+id+'&rnd=' + new Date().getTime();
    var looklist = window.localStorage.getItem("bookList").split('#');
    var lookid = looklist.indexOf(id);if(lookid<0){return false;}
    var lastbook = window.localStorage.getItem(looklist[lookid]).split('#');
	$(".readlink .rl").attr('href', '/book/' + id + '/' + lastbook[1] + '.html');
	$(".readlink .rl").attr('title', '上次阅读到：' + lastbook[3]);
	$(".readlink .rl").text('继续阅读');
}
function reads(){
	
}
function read2(){

}
function read3(){
	$(".noshow").hide();
}
function list2(){

	//document.writeln("<div class=\'wrap\'>");
	//read2();
	//document.writeln("</div>");
}

function get_bookpage(id,num){
	if(num=="n"){page++;}else if(num=="p"){if(page<=1){alert('已经是第一页了!');return false;}page--;}else{page=num;}
    $.getJSON("/json_book?id="+id+"&page="+page,function(data){
		var strHtml = "";
		$.each(data,function(index,val){
			strHtml += '<li><a href="./'+(page*20-20+index+1)+'.html">'+val+'</a></li>';
		})
		if(strHtml==""){alert('没有了!');return false;}
		$(".allup").html(strHtml);$("select option[value="+page+"]").attr("selected", true);
	});
}
function get_booklist(id){
    $.getJSON("/json_book?id="+id+"&page=0",function(data){
		var strHtml = "";
		$.each(data,function(index,val){
			strHtml += '<li><a href="./'+(index+1)+'.html">'+val+'</a></li>';
		})
		if(strHtml==""){alert('没有了!');return false;}
		$(".allup").html(strHtml);$(".listpage").hide();
	});
}
function topCase(){
	var sURL = "http://"+location.hostname;
	var sTitle = "笔趣阁";
	try{
		window.external.addFavorite(sURL, document.title);
	}catch (e){
		try{
window.sidebar.addPanel(sTitle, sURL, "");
		}catch (e){
alert("加入收藏失败，请使用Ctrl+D进行添加");
		}
	}
}
function setHome(){
	var url = "http://"+location.hostname;
	if (document.all){
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	}else{
		alert("操作被浏览器拒绝,请手动在浏览器里设置该页面为首页！");
	}
}

function logout(){
	setCookie("username",'',1);location.reload();
}
function post_register(userName,passWord,repassWord){
    $.post("/user/action.html",
       { action: "register", username: userName,password: passWord, repassword: repassWord},
       function(data){
            if(data==0)
            {
		$("#dy_tips").html("请输入用户名、密码！");
            }
            else if(data==2)
            {
		$("#dy_tips").html("两次输入的密码不一样，请重新修改密码！");
            }
            else if(data==-1)
            {
		$("#dy_tips").html("此用户已存在，请重新注册！");
            }
            else if(data==1)
            {
		$("#dy_tips").html("注册成功，欢迎您："+userName);location.href = "/user/bookcase.html";
            }else{$("#dy_tips").html("注册失败，请稍后重新注册！");}
 
        }
    );
}
function post_login(userName,passWord){
    $.post("/user/action.html",
       { action: "login", username: userName,password: passWord},
       function(data){
            if(data==0)
            {
		$("#dy_tips").html("请输入用户名、密码！");
            }
            else if(data==-1)
            {
		$("#dy_tips").html("密码错误或用户不存在，请重新登陆！");
            }
            else if(data==1)
            {
		$("#dy_tips").html("登陆成功，欢迎您："+userName);
		location.reload();//location.href = "/user/bookcase.html";
            }else{$("#dy_tips").html("登陆失败，请稍后重新登陆！");}
        }
    );
}
function doParse(url) {
	var params = {};
	if (! url ) return params;
	var paramPart = url.substring(url.indexOf("?") + 1);
	var parts = paramPart.split("&");
	for(var i = 0; i < parts.length; i++) {
		var index = parts[i].indexOf("=");
		if (index == -1) continue;
		params[parts[i].substring(0, index)] = parts[i].substring(index + 1); 
	}
	return params;
}
function addBookCase(bookid){
	$.post("/user/action.html",
        { action: "addbook", bookid: bookid },
        function(data){
            if(data==-1)
            {
              location.href = "/login.html?jumpurl="+location.href;
            }
            else if(data==0)
            {
                alert("书架已满，加入书架出错！");
            }
            else if(data==1)
            {
                alert("加入书架成功！");
            }
            else if(data==2)
            {
                alert("该书已在书架中！");
           }else{alert("加入书架出错！");}
        }
    );
}
function addBookMark(bookId,chapterId,articleName,chapterName){
    $.post("/user/action.html",
       { action: "addbook",bookid: bookId, chapterid:chapterId, articlename: articleName, chaptername: chapterName },
       function(data){
            if(data==-1)
            {
				alert("您还没有登录，请登录后再加入书签！");
				location.href = "/login.html?jumpurl="+location.href+"#footer";
            }
            else if(data==0)
            {
                alert("书架已满，加入书架出错！");
            }
            else if(data==1)
            {
                alert("加入书签成功！");
            }else{alert("加入书签出错！");}
 
        }
    );
}
function chapter_error(bookId,chapterId,articleName,chapterName,Time){
if (confirm('你确定这章节有错吗？')) {
    $.post("/user/action.html",
       { action: "chapter_error", bookid: bookId, chapterid:chapterId, articlename: articleName, chaptername: chapterName, time: Time},
       function(data){
            if(data==1)
            {
				alert("举报错误章节成功，请耐心等待维护人员处理~");
            }
			else if(data>10)
            {
				window.location.href=window.location.href+'?'+data;
			}
			else{
				alert("请不要频繁提交~");
			}
        }
    );
}
}
function book_error(bookId,articleName,Time){
if (confirm('你确定本书更新出错吗？')) {
    $.post("/user/action.html",
       { action: "book_error", bookid: bookId, articlename: articleName, time: Time},
       function(data){
            if(data==1)
            {
				//alert("举报错误成功，请耐心等待维护人员处理~");
				if (confirm('举报错误成功，是否登陆留言给管理员？')) {
					window.location.href= '/user/book.html?action=add&bookid='+bookId+'&title='+'《'+articleName+'》报错：';
				}
            }
			else if(data>10)
            {
				window.location.href=window.location.href+'?'+data;
			}
			else{
				alert("请不要频繁提交~~~");
			}
        }
    );
}
}
$(function(){
    document.body.insertAdjacentHTML("afterBegin", '<div hidden>' +
        '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" style="width:0;height:0;position:absolute;overflow:hidden;">' +
        '<defs><symbol id="lnr-magnifier" viewBox="0 0 1024 1024"><title>magnifier</title><path class="path1" d="M966.070 981.101l-304.302-331.965c68.573-71.754 106.232-165.549 106.232-265.136 0-102.57-39.942-199-112.47-271.53s-168.96-112.47-271.53-112.47-199 39.942-271.53 112.47-112.47 168.96-112.47 271.53 39.942 199.002 112.47 271.53 168.96 112.47 271.53 112.47c88.362 0 172.152-29.667 240.043-84.248l304.285 331.947c5.050 5.507 11.954 8.301 18.878 8.301 6.179 0 12.378-2.226 17.293-6.728 10.421-9.555 11.126-25.749 1.571-36.171zM51.2 384c0-183.506 149.294-332.8 332.8-332.8s332.8 149.294 332.8 332.8-149.294 332.8-332.8 332.8-332.8-149.294-332.8-332.8z"></path></symbol>' +
        '<symbol id="lnr-home" viewBox="0 0 1024 1024"><title>home</title><path class="path1" d="M1017.382 622.826l-452.050-499.634c-14.051-15.533-32.992-24.086-53.333-24.086-0.002 0 0 0 0 0-20.339 0-39.282 8.555-53.334 24.086l-452.050 499.634c-9.485 10.485-8.675 26.674 1.808 36.158 4.899 4.432 11.043 6.616 17.168 6.616 6.982 0 13.938-2.838 18.992-8.426l109.016-120.491v410.517c0 42.347 34.453 76.8 76.8 76.8h563.2c42.347 0 76.8-34.453 76.8-76.8v-410.517l109.018 120.493c9.485 10.483 25.674 11.296 36.158 1.808 10.483-9.485 11.293-25.675 1.806-36.158zM614.4 972.8h-204.8v-230.4c0-14.115 11.485-25.6 25.6-25.6h153.6c14.115 0 25.6 11.485 25.6 25.6v230.4zM819.2 947.2c0 14.115-11.485 25.6-25.6 25.6h-128v-230.4c0-42.349-34.451-76.8-76.8-76.8h-153.6c-42.347 0-76.8 34.451-76.8 76.8v230.4h-128c-14.115 0-25.6-11.485-25.6-25.6v-467.106l291.832-322.552c4.222-4.667 9.68-7.237 15.368-7.237s11.146 2.57 15.366 7.235l291.834 322.552v467.107z"></path></symbol>' +
        '<symbol id="lnr-arrow-up-circle" viewBox="0 0 1024 1024"><title>arrow-up-circle</title><path class="path1" d="M142.464 193.662c-91.869 91.869-142.464 214.016-142.464 343.938s50.595 252.067 142.464 343.936 214.014 142.464 343.936 142.464 252.069-50.595 343.938-142.464 142.462-214.014 142.462-343.936-50.594-252.069-142.462-343.938-214.016-142.462-343.938-142.462-252.067 50.594-343.936 142.462zM921.6 537.6c0 239.97-195.23 435.2-435.2 435.2s-435.2-195.23-435.2-435.2c0-239.97 195.23-435.2 435.2-435.2s435.2 195.23 435.2 435.2z"></path><path class="path2" d="M468.301 237.901l-204.8 204.8c-9.998 9.995-9.998 26.206 0 36.203 9.997 9.998 26.206 9.998 36.203 0l161.096-161.101v526.997c0 14.138 11.461 25.6 25.6 25.6s25.6-11.462 25.6-25.6v-526.997l161.101 161.096c9.995 9.998 26.206 9.998 36.203 0 4.997-4.997 7.496-11.547 7.496-18.099s-2.499-13.102-7.501-18.099l-204.8-204.8c-9.997-10-26.202-10-36.198 0z"></path></symbol>' +
        '<symbol id="lnr-chevron-left-circle" viewBox="0 0 1024 1024"><title>chevron-left-circle</title><path class="path1" d="M142.462 193.664c91.869-91.869 214.016-142.464 343.938-142.464s252.067 50.595 343.936 142.464 142.464 214.014 142.464 343.936-50.595 252.069-142.464 343.938-214.014 142.462-343.936 142.462-252.069-50.594-343.938-142.462-142.462-214.016-142.462-343.938 50.594-252.067 142.462-343.936zM486.4 972.8c239.97 0 435.2-195.23 435.2-435.2s-195.23-435.2-435.2-435.2c-239.97 0-435.2 195.23-435.2 435.2s195.23 435.2 435.2 435.2z"></path><path class="path2" d="M563.2 819.2c6.552 0 13.102-2.499 18.102-7.499 9.997-9.997 9.997-26.206 0-36.203l-237.898-237.898 237.898-237.898c9.997-9.998 9.997-26.206 0-36.205-9.998-9.997-26.206-9.997-36.205 0l-256 256c-9.998 9.997-9.998 26.206 0 36.203l256 256c5 5 11.55 7.499 18.102 7.499z"></path></symbol>' +
        '<symbol id="lnr-chevron-down" viewBox="0 0 1024 1024"><title>chevron-down</title><path class="path1" d="M0 307.2c0-6.552 2.499-13.102 7.499-18.101 9.997-9.998 26.206-9.998 36.203 0l442.698 442.698 442.699-442.698c9.997-9.998 26.206-9.998 36.203 0s9.998 26.206 0 36.203l-460.8 460.8c-9.997 9.998-26.206 9.998-36.203 0l-460.8-460.8c-5-5-7.499-11.55-7.499-18.102z"></path></symbol>' +
        '<symbol id="lnr-user" viewBox="0 0 1024 1024"><title>user</title><path class="path1" d="M486.4 563.2c-155.275 0-281.6-126.325-281.6-281.6s126.325-281.6 281.6-281.6 281.6 126.325 281.6 281.6-126.325 281.6-281.6 281.6zM486.4 51.2c-127.043 0-230.4 103.357-230.4 230.4s103.357 230.4 230.4 230.4c127.042 0 230.4-103.357 230.4-230.4s-103.358-230.4-230.4-230.4z"></path><path class="path2" d="M896 1024h-819.2c-42.347 0-76.8-34.451-76.8-76.8 0-3.485 0.712-86.285 62.72-168.96 36.094-48.126 85.514-86.36 146.883-113.634 74.957-33.314 168.085-50.206 276.797-50.206 108.71 0 201.838 16.893 276.797 50.206 61.37 27.275 110.789 65.507 146.883 113.634 62.008 82.675 62.72 165.475 62.72 168.96 0 42.349-34.451 76.8-76.8 76.8zM486.4 665.6c-178.52 0-310.267 48.789-381 141.093-53.011 69.174-54.195 139.904-54.2 140.61 0 14.013 11.485 25.498 25.6 25.498h819.2c14.115 0 25.6-11.485 25.6-25.6-0.006-0.603-1.189-71.333-54.198-140.507-70.734-92.304-202.483-141.093-381.002-141.093z"></path></symbol>' +
        '<symbol id="lnr-chevron-down-circle" viewBox="0 0 1024 1024"><title>chevron-down-circle</title><path class="path1" d="M830.336 881.538c91.869-91.869 142.464-214.016 142.464-343.938s-50.595-252.067-142.464-343.936-214.014-142.464-343.936-142.464-252.069 50.595-343.938 142.464-142.462 214.014-142.462 343.936 50.594 252.069 142.462 343.938 214.016 142.462 343.938 142.462 252.067-50.594 343.936-142.462zM51.2 537.6c0-239.97 195.23-435.2 435.2-435.2s435.2 195.23 435.2 435.2c0 239.97-195.23 435.2-435.2 435.2s-435.2-195.23-435.2-435.2z"></path><path class="path2" d="M204.8 460.8c0-6.552 2.499-13.102 7.499-18.102 9.997-9.997 26.206-9.997 36.203 0l237.898 237.898 237.898-237.898c9.998-9.997 26.206-9.997 36.205 0 9.997 9.998 9.997 26.206 0 36.205l-256 256c-9.997 9.998-26.206 9.998-36.203 0l-256-256c-5-5-7.499-11.55-7.499-18.102z"></path></symbol>' +
        '<symbol id="lnr-lock" viewBox="0 0 1024 1024"><title>lock</title><path class="path1" d="M742.4 409.6h-25.6v-76.8c0-127.043-103.357-230.4-230.4-230.4s-230.4 103.357-230.4 230.4v76.8h-25.6c-42.347 0-76.8 34.453-76.8 76.8v409.6c0 42.347 34.453 76.8 76.8 76.8h512c42.347 0 76.8-34.453 76.8-76.8v-409.6c0-42.347-34.453-76.8-76.8-76.8zM307.2 332.8c0-98.811 80.389-179.2 179.2-179.2s179.2 80.389 179.2 179.2v76.8h-358.4v-76.8zM768 896c0 14.115-11.485 25.6-25.6 25.6h-512c-14.115 0-25.6-11.485-25.6-25.6v-409.6c0-14.115 11.485-25.6 25.6-25.6h512c14.115 0 25.6 11.485 25.6 25.6v409.6z"></path></symbol>' +
        '<symbol id="applogo" viewBox="0 0 100 100"><g><path d="M26.795,51.639c-1.073,0.224-1.869,1.127-1.869,2.224v31.988c0,0.667,0.294,1.3,0.805,1.729,c0.51,0.429,1.184,0.61,1.842,0.495l3.402-0.594c6.028-1.054,12.206-0.776,18.119,0.772V51.682,C43.181,50.132,36.274,49.665,26.795,51.639z"></path><path d="M73.575,51.639c-9.479-1.974-16.386-1.507-22.299,0.043v36.571c5.913-1.549,12.091-1.826,18.119-0.772l3.402,0.594,c0.658,0.115,1.332-0.066,1.842-0.495c0.511-0.429,0.805-1.062,0.805-1.729V53.862C75.444,52.766,74.648,51.862,73.575,51.639z"></path><path d="M79.477,25.781c-0.545-0.039-1.047-0.318-1.366-0.762c-4.003-5.553-10.525-8.988-17.469-8.988,c-0.504,0-1.008,0.018-1.511,0.053c-0.451,0.032-0.896-0.103-1.254-0.378c-4.204-3.233-9.327-4.987-14.695-4.987,c-9.595,0-18.096,5.623-21.968,14.108c-0.267,0.583-0.816,0.985-1.452,1.065C9.157,27.219,0.924,36.29,0.924,47.248,c0,11.273,8.718,20.532,19.763,21.434v-8.524c-6.36-0.863-11.283-6.315-11.283-12.909c0-7.192,5.852-13.043,13.044-13.043,c0.363,0,0.72,0.029,1.075,0.059c2.072,0.16,3.95-1.185,4.454-3.194c1.755-6.989,8.007-11.871,15.205-11.871,c4.111,0,8.003,1.588,10.959,4.472c1.01,0.985,2.443,1.405,3.826,1.117c0.88-0.184,1.779-0.276,2.675-0.276,c5.035,0,9.531,2.831,11.735,7.388c0.774,1.603,2.467,2.556,4.238,2.373c0.441-0.043,0.881-0.066,1.309-0.066,c7.192,0,13.043,5.851,13.043,13.043c0,6.594-4.922,12.046-11.283,12.91v8.523c11.046-0.901,19.763-10.16,19.763-21.434,C99.446,35.903,90.622,26.58,79.477,25.781z"></path></g></symbol>' + 
        '</defs></svg></div>')
});
